package grouuu.input;

import openfl.display.Stage;
import openfl.events.MouseEvent;
import openfl.geom.Point;

/**
 * ...
 * @author Grouuu
 */
class Mouse
{
	private var stage:Stage;
	private var callback:Point->Void;

	public function new(stage:Stage) 
	{
		this.stage = stage;
	}
	
	// CONTROL ////////////////////////////////////////////////////////////////////////////////////
	
	public function start(callback:Point->Void):Void
	{
		this.callback = callback;
		
		stage.addEventListener(MouseEvent.CLICK, onClick);
	}
	
	public function stop():Void
	{
		stage.removeEventListener(MouseEvent.CLICK, onClick);
	}
	
	// EVENT //////////////////////////////////////////////////////////////////////////////////////
	
	private function onClick(e:MouseEvent):Void
	{
		callback(new Point(e.stageX, e.stageY));
	}
}